home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
diskutil
/
mutate.lzh
/
MUTATE.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-05-13
|
16KB
|
807 lines
#include <aes.h>
#include <linea.h>
#include <tos.h>
#include <stdio.h>
#include <stdlib.h>
#include <ext.h>
#include <ctype.h>
#include <string.h>
#include <mydefs.h>
#include "mutate.h"
char *pbase;
long ramtop;
long rambot;
int changed;
int cdrive;
int coffst;
#define MODEM 0
#define MODEF 1
#define MODED 2
struct
{
unt bps; /* bytes per sector */
unt spc; /* sectors per cluster */
unt bpc; /* bytes per cluster */
unt res; /* */
unt fat; /* number of fats */
unt dir; /* # of dir entries */
unt sec; /* # of sectors / disk */
unt spf; /* # of sectors / fat */
unt spt; /* # of sectors / track */
unt sid; /* # of sides */
unt hid; /* # of hidden */
unt bpe; /* bytes per fat entry */
unt cpf; /* clusters per fat */
unt cps; /* clusters per system */
unt cpd; /* clusters per direct. */
unt sps; /* sectors per system */
unt spd; /* sectors per direct. */
unt bad; /* bad clusters on disk */
unt dcl; /* data clusters on disk*/
unt clu; /* total clusters/disk */
} boot;
/***********
blink cursor at x,y
***********/
long cblink(int x, int y, int a)
{
long cx,cy;
register int i;
if (!a)
cx=(long)x+13+(coffst==0)*(x/4);
else
cx=(long)x/2+53;
cy=(long)y*16+108-coffst;
while(!Cconis())
{
for(i=0;i<16;i++)
*(pbase+cx+((cy+i)*80))^=0xff;
if (!Cconis())
delay(100);
for(i=0;i<16;i++)
*(pbase+cx+((cy+i)*80))^=0xff;
if (!Cconis())
delay(100);
}
return(Crawcin());
}
/***********
print at x,y
***********/
void printxy(int x, int y, int a, uch c)
{
long cx,cy;
register int i;
Bconout(2,27);
Bconout(2,'H');
Bconout(2,(int)c);
if (!a)
cx=(long)x+13+(x/4);
else
cx=(long)x/2+53;
cy=(long)y*16+108;
for(i=0;i<16;i++)
{
*(pbase+cx+((cy+i)*80))=*(pbase+i*80);
*(pbase+i*80)=0;
}
}
/***********
Get a long hex input
***********/
long getlong(int x, int y, long old, int box, int item)
{
int c;
long k,l;
int p,done;
l=0;
p=0;
done=0;
while(p<7&&!done)
{
sprintf(rs_object[rs_trloc[box]+item].ob_spec.free_string,"%lx",l);
dial_draw(box,item);
k=cblink(x+p,y,0);
c=(int)k;
if ((c==0)||(k==0xE0008L))
{
if (((k==0x4d0000L)||(k==0xE0008L))&&(p>0))
{
p-=1;
l=l>>4;
}
else
done=1;
}
else if ((done=(c==13))==0)
{
if (islower(c)) c=toupper(c);
if ((c<'0')||(c>'F')||((c>'9')&&(c<'A')))
printf("\007");
else
{
if (c>'9')
c=c-55;
else
c=c-48;
l=((l<<4)|c);
++p;
}
}
}
if (c==13)
return(l);
else
return(old);
}
/***********
Supervisor Peek
***********/
long speekl;
long speekv;
void speek(void)
{
speekv=*(long *)speekl;
}
/***********
Supervisor Poke
***********/
void spoke(void)
{
*(long *)speekl=speekv;
}
/***********
Peek a long word
***********/
long peek(long loc)
{
if ((loc<ramtop)&&(loc>rambot))
return(*(long *)loc);
else
{
speekl=loc;
Supexec(speek);
return(speekv);
}
}
/**********
Poke a long word
**********/
void poke(long loc, long val)
{
if ((loc<ramtop)&&(loc>rambot))
*(long *)loc=val;
else
{
speekl=loc;
speekv=val;
Supexec(spoke);
}
}
/***********
Getfile
***********/
int getfile(uch **buf, long *size)
{
int c,fd;
long l;
static char *f="FILENAME.EXT";
static char *p="A:\\*.*\0 ";
char q[128];
uch *b;
*p='A'+(char)Dgetdrv();
fsel_exinput(p,f,&c,"Choose a file to MUTATE!");
if (c)
{
Dsetdrv((int)*p-65);
strcpy(q,p+2);
strcpy(strrchr(q,'\\')+1,f);
if (Fsfirst(q,0)>=0)
{
Fgetdta();
fd=Fopen(q,READ);
l=filelength(fd);
if ((b=malloc(l))!=NULL)
{
if (*buf!=NULL)
free(*buf);
*buf=b;
strcpy(rs_object[rs_trloc[MAIN]+MAINFNAM].ob_spec.free_string,f);
dial_draw(MAIN,MAINFNAM);
Fread(fd,l,*buf);
*size=l;
Fclose(fd);
return(1);
}
else
{
Fclose(fd);
return(0);
}
}
else
return(0);
}
else
return(0);
}
/***********
Putfile
***********/
int putfile(uch *buf, long size)
{
int c,fd;
static char *f="FILENAME.EXT";
static char *p="A:\\*.*\0 ";
char q[128];
*p='A'+(char)Dgetdrv();
fsel_exinput(p,f,&c,"Choose a file to save the MUTATION!");
if (c)
{
Dsetdrv((int)*p-65);
strcpy(q,p+2);
strcpy(strrchr(q,'\\')+1,f);
fd=1;
if (Fsfirst(q,0)>=0)
{
Fgetdta();
fd=mess2("Do you wish to","overwrite?","NO","YES",1);
}
if (fd)
{
Fdelete(f);
fd=Fcreate(f,0);
Fclose(fd);
fd=Fopen(q,WRITE);
Fwrite(fd,size,buf);
Fclose(fd);
return(1);
}
else
return(putfile(buf,size));
}
else
return(0);
}
/****************************
Check in disk & set info
****************************/
void dmapdriv(int drive)
{
long e;
unt *buf;
buf = (unt *)malloc(0x2000);
Dsetdrv(drive);
if (Mediach(drive))
Getbpb(drive);
if ((e=Rwabs(READ+2,buf,1,0,drive))!=0)
{
mess("Boot read error!");
messl(e);
}
else
{
boot.bps = (buf[5]&0x00ff)+(buf[6]&0xff00);
boot.spc = (buf[6]&0x00ff);
boot.res = ((buf[7]&0x00ff)<<8)+((buf[7]&0xff00)>>8);
boot.fat = (buf[8]&0xff00)>>8;
boot.dir = (buf[8]&0x00ff)+(buf[9]&0xff00);
boot.sec = (buf[9]&0x00ff)+(buf[10]&0xff00);
boot.spf = ((buf[11]&0x00ff)<<8)+((buf[11]&0xff00)>>8);
boot.spt = ((buf[12]&0x00ff)<<8)+((buf[12]&0xff00)>>8);
boot.sid = ((buf[13]&0x00ff)<<8)+((buf[13]&0xff00)>>8);
boot.hid = ((buf[14]&0x00ff)<<8)+((buf[14]&0xff00)>>8);
boot.bpc = (boot.bps * boot.spc);
boot.spd = (boot.dir / (boot.bps/0x20) * (boot.bps/0x200));
boot.cpd =((boot.spd +1)/ boot.spc);
boot.cpf = (boot.spf / boot.spc) * boot.fat * (boot.bps/0x200);
boot.cps = (boot.cpf + boot.cpd);
boot.sps =((boot.spf * boot.fat) + boot.spd);
boot.dcl =((boot.sec-boot.sps)/boot.spc);
boot.clu = (boot.dcl + boot.cps);
boot.bpe = 4;
if (drive < 2) boot.bpe = 3;
}
free(buf);
}
/***********
Check for Update
***********/
void putbuf(int mode, uch *buf, long boff, long bufsize)
{
long l,m;
if (changed)
{
changed=0;
if (mess2("Do you wish to","make changes permanent","NO","YES",0))
{
switch(mode)
{
case MODEM:
for(l=0L;(l<bufsize)&&(l+boff<ramtop);l+=4)
poke(l+boff,*((long *)(buf+l)));
break;
case MODEF:
putfile(buf,bufsize);
break;
case MODED:
dmapdriv(cdrive);
l=bufsize/boot.bps;
m=boff/boot.bps;
if (Rwabs(WRITE+2,buf,(int)l,(int)m,cdrive)<0)
mess("CAREFUL! Write Error");
break;
}
}
}
}
/***********
Fill the buffer with data
***********/
void fillbuf(int mode, uch *buf, long boff, long bufsize)
{
long l,m;
putbuf(mode,buf,boff,bufsize);
switch (mode)
{
case MODEM:
for(l=0L;l<bufsize;l+=4)
*((long *)(buf+l))=peek(l+boff);
break;
case MODEF:
break;
case MODED:
dmapdriv(cdrive);
l=bufsize/boot.bps;
m=boff/boot.bps;
if (Rwabs(READ+2,buf,(int)l,(int)m,cdrive)<0)
mess("CAREFUL! Read Error");
break;
}
}
/***********
Update the window
***********/
void update(long offset, long boff, long bufsize, uch *buf)
{
int i,j;
long m;
long l;
uch c;
char s[5];
for(i=0,l=0L;(l<0xa0L)&&(l<bufsize-offset);l+=0x10,i++)
{
sprintf(rs_object[rs_trloc[MAIN]+MAINSTR0+i].ob_spec.tedinfo->te_ptext,
"%6lx",l+offset);
*(rs_object[rs_trloc[MAIN]+MAINSTR0+i].ob_spec.tedinfo->te_ptext+6)=':';
for(m=0;(m<16)&&(l+m<bufsize-offset);m++)
{
c=*(buf+l+m);
sprintf(s,"%4x",(unt)c);
if (*(s+2)==' ')
*(s+2)='0';
if (c==0)
c=0x2e;
*(rs_object[rs_trloc[MAIN]+MAINSTR0+i].ob_spec.tedinfo->te_ptext+m+47)=c;
for(j=0;j<2;j++)
*(rs_object[rs_trloc[MAIN]+MAINSTR0+i].ob_spec.tedinfo->te_ptext+j+m*2+m/2+7)=s[j+2];
}
}
sprintf(rs_object[rs_trloc[MAIN]+MAINOFFS].ob_